package com.company;

import java.util.Scanner;

public class Sense {
    private Person person = new Person();
    private MonsterWolf wolf1=new MonsterWolf();
    private MonsterWolf wolf2=new MonsterWolf();
    private  MonsterWolf wolf3=new MonsterWolf();

    private MonsterWolfSet monsterWolfSet=new MonsterWolfSet();
    Ui ui=new Ui();
    public Sense(){

    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public MonsterWolfSet getMonsterWolfSet() {
        return monsterWolfSet;
    }

    public void setMonsterWolfSet(MonsterWolfSet monsterWolfSet) {
        this.monsterWolfSet = monsterWolfSet;
    }



    public void initSense(){
        initPerson();
        initMonster();
    }

    public void initPerson(){
        person.setId("201902136");
        person.setDescription("老超");
        person.setHPVaule(300);
        person.setCurrentWeapon(new WeaponSword("pw1","屠龙剑",-50));
    }

    public void initMonster(){
        wolf1.setId("wolf1");
        wolf1.setDescription("狼1");
        wolf1.setHPVaule(200);
        wolf1.setCurrentWeapon(new WeaponKnife("mw1","大刀1",-30));

        wolf2.setId("wolf2");
        wolf2.setDescription("狼2");
        wolf2.setHPVaule(200);
        wolf2.setCurrentWeapon(new WeaponKnife("mw2","大刀2",-20));

        wolf3.setId("wolf3");
        wolf3.setDescription("狼3");
        wolf3.setHPVaule(200);
        wolf3.setCurrentWeapon(new WeaponKnife("mw3","大刀3",-25));

        monsterWolfSet.getMonsterWolves().add(wolf1);
        monsterWolfSet.getMonsterWolves().add(wolf2);
        monsterWolfSet.getMonsterWolves().add(wolf3);
    }

    public boolean judgeSuccess(){
        boolean flagPersonSuccess=true;//人胜利

        if (this.getPerson().getHPVaule() <=0){
            flagPersonSuccess=false;
        }


        return flagPersonSuccess;
    }

    //测试
    public void play(){
        ui.displayStaus(this);
        ui.displayHelpMsg();
        wolf1.useArticle(person.getCurrentWeapon(),wolf1);
        Scanner in=new Scanner(System.in);

        while (true){
            //用户输入命令
            String command =in.nextLine();
            //分割命令行各个单元
            String[] words = command.split(" ");
            if(words[0].equals("bye"))
            {
                ui.displayBye();
                System.exit( 0);
            }
            else if(words[0].equals("help")){

                ui.displayHelpMsg();
//                ui.displayStaus(this);
            }
            else if(words[0].equals("chop")){
//                ui.CreatureInformationDiaplay(this);
//                this.getPerson().useArticle(getPerson().getCurrentWeapon(),this.getMonsterWolfSet().getMonsterWolves().);
               this.getPerson().useArticle(this.getPerson().getCurrentWeapon(),this.getMonsterWolfSet().get(words[1]));
//               ui.CreatureInformationDiaplay(this);
                ui.displayDamagemsg(this.getPerson(),this.getMonsterWolfSet().get(words[1]));
                //妖怪随机砍人，有时候不砍

                for(MonsterWolf item:this.getMonsterWolfSet().getMonsterWolves()){
                    if(1==Utils.randomMonsterChop()){
                        item.useArticle(item.getCurrentWeapon(),this.getPerson());
                        ui.displayDamagemsg(item,this.getPerson());
                    }
                }

            }
            else{
                ui.displayErrorCmdMsg();
                ui.displayHelpMsg();
            }
            ui.displayStaus(this);
            if (judgeSuccess()==false){
                System.out.println("人失败，游戏结束");
                System.exit(0);
            }

        }
    }


}
